<template>
  <div style="height:100%;width:100%;position:relative;">
      <div class="page-container">
          <div class="page-top" style="border:1px solid #CCC">
              <div class="search-title">快速查询</div>
              <el-input v-model="searchParam" placeholder="请输入培养基代码、培养基名称、录入码" @keyup.enter.native="filterData" :disabled="changeflag" clearable style="width: 260px;"></el-input>
              <div class="top-deal">
                  <el-button icon="el-icon-search" type="primary" @click="filterData" :disabled="changeflag">查询</el-button>
                  <el-button icon="el-icon-plus" @click="MainOpenDialog(1)" :disabled="changeflag">新增</el-button>
                  <el-button icon="el-icon-delete" @click="MainOpenDialog(2)" :disabled="changeflag">删除</el-button>
                  <el-button icon="el-icon-document" @click="MainOpenDialog(3)" :disabled="!changeflag">保存</el-button>
                  <el-button icon="el-icon-close" @click="MainOpenDialog(4)" :disabled="!changeflag">取消</el-button>
                  <el-button icon="el-icon-files" @click="ImportCsv" ref="importFile" :disabled="changeflag">导入</el-button>
                  <div class="upload-button">
                      <el-upload ref="upload" :action="url" accept=".dat" :before-upload="beforeUploadFile" :on-change="fileChange" :show-file-list="showFile" :data="updata" :http-request="uploadOpt">
                          <el-button size="small" plain>选择文件</el-button>
                          <!-- <div slot="tip" class="el-upload__tip">只能上传DAT(*dat)文件，且不超过10M</div> -->
                      </el-upload>
                  </div>
                  <el-button icon="el-icon-upload2" @click="ExportCsv" style="margin-left: 10px" :disabled="changeflag">导出</el-button>
              </div>
          </div>
          <div class="page-bottom">
              <rm-layout-right splitcolor="#FFFFFF" movingcolor="#CCFFFF" :splitwidth=5 :fixsize=534>
                  <div class="middle-left" style="height:100%">
                      <vxe-table show-overflow ref="xTable" :data.sync="mediumList" class="mytable-style" height="auto" 
                          :loading="mediumLoading" :sort-config="{trigger: 'cell'}" :keyboard-local-config="keyLocalConfig" 
                          border size="mini" highlight-current-row resizable stripe 
                          header-align="center" :row-class-name="rowClassName" @current-change="currentChangeEvent">
                          <vxe-table-column field="mediumno" title="培养基代码" width="90"></vxe-table-column>
                          <vxe-table-column field="mediumname" title="培养基名称" width="120"></vxe-table-column>
                          <vxe-table-column field="conidtions" title="培养条件" width="180"></vxe-table-column>
                          <vxe-table-column field="culturehour" title="培养周期(小时)" width="60"></vxe-table-column>
                          <vxe-table-column field="watchinterval" title="观察间隔(小时)" width="60"></vxe-table-column>
                          <vxe-table-column field="watchinterval" title="血培养容器" width="80"></vxe-table-column>
                          <vxe-table-column field="comments" title="备注" width="100"></vxe-table-column>
                          <vxe-table-column field="inputcode" title="录入码" width="100"></vxe-table-column>
                          <vxe-table-column field="seq" title="序号" width="40" align="center"></vxe-table-column>
                          <vxe-table-column field="noprintbar" title="不打印标签" align="center" width="40">
                              <template v-slot="{ row }">
                                  <el-checkbox v-model="row.noprintbar" true-label="1" false-label="0" disabled></el-checkbox>
                              </template>
                          </vxe-table-column>
                          <vxe-table-column field="autobottleno" title="自动开窗容器号" align="center" width="60">
                              <template v-slot="{ row }">
                                  <el-checkbox v-model="row.autobottleno" true-label="1" false-label="0" disabled></el-checkbox>
                              </template>
                          </vxe-table-column>
                      </vxe-table>
                  </div>
                  <template v-slot:fix>
                      <div class="middle-right" style="height:100%;">
                          <el-tabs v-model="activeName" @tab-click="handleTabClick" style="height:100%;" type="border-card" ref="tabs">
                              <el-tab-pane label="基本信息" name="baseinfo">
                                  <table>
                                      <tr>
                                          <td class="must-param" width="80" align="right">培养基代码</td>
                                          <td>
                                              <el-input v-model="addParam.mediumno" :disabled="operatetype != 1" @input="hasChange" ref="input11" @keyup.enter.native="nextFocus(1, 1)"></el-input>
                                          </td>
                                          <td></td>
                                          <td colspan="2">
                                              <el-checkbox v-model="addParam.noprintbar" true-label="1" false-label="0" @change="hasChange"></el-checkbox> 不打印标签
                                          </td>
                                          <td></td>
                                          <td>
                                              <el-checkbox v-model="addParam.bloodculture" true-label="1" false-label="0" @change="hasChange"></el-checkbox> 血培养标志
                                          </td>
                                      </tr>
                                      <tr>
                                          <td class="must-param" align="right">培养基名称</td>
                                          <td colspan="6">
                                              <el-input v-model="addParam.mediumname" @input="inputCodeChange" ref="input12" @keyup.enter.native="nextFocus(1, 2)"></el-input>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td align="right">培养条件</td>
                                          <td colspan="6">
                                              <el-input v-model="addParam.conidtions" @input="hasChange" ref="input13" @keyup.enter.native="nextFocus(1, 3)"></el-input>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td align="right">培养周期(小时)</td>
                                          <td>
                                              <el-input v-model="addParam.culturehour" @input="hasChange" ref="input14" @keyup.enter.native="nextFocus(1, 4)"></el-input>
                                          </td>
                                          <td colspan="3" align="right">观察间隔(小时)</td>
                                          <td colspan="2">
                                              <el-input v-model="addParam.watchinterval" @input="hasChange" ref="input15" @keyup.enter.native="nextFocus(1, 5)"></el-input>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td align="right">对应报告项目</td>
                                          <td colspan="6">
                                              <rm-ddl-rptitem prgno="LIS833" @change="rptitemchange" :germmode="true" v-model="addParam.rpt_itemcode" ref="input16" @keyup.enter.native="nextFocus(1, 6)" width="100%"></rm-ddl-rptitem>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td align="right">备注</td>
                                          <td colspan="6">
                                              <el-input v-model="addParam.comments" @input="hasChange" ref="input17" @keyup.enter.native="nextFocus(1, 7)"></el-input>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td align="right">录入码</td>
                                          <td>
                                              <el-input v-model="addParam.inputcode" maxlength="20" @input="hasChange" ref="input18" @keyup.enter.native="nextFocus(1, 8)"></el-input>
                                          </td>
                                          <td width="30" align="right">序号</td>
                                          <td width="75">
                                              <el-input v-model="addParam.seq" @input="hasChange" ref="input19" @keyup.enter.native="nextFocus(1, 9)"></el-input>
                                          </td>
                                          <td colspan="3">
                                              <el-checkbox v-model="addParam.autobottleno" true-label="1" false-label="0" @change="hasChange"></el-checkbox> 自动开窗扫描容器号码
                                          </td>
                                      </tr>
                                      <tr class="search-textarea" style="width: 100% !important;">
                                          <td align="right" style="vertical-align:top">容器条码前缀(多个用，隔开)</td>
                                          <td colspan="6">
                                              <el-input type="textarea" v-model="addParam.bottlenohead" @input="hasChange" rows="3" ref="input110" @keyup.enter.native="nextFocus(1, 10)"></el-input>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td align="right">容器条码长度(多个用，隔开)</td>
                                          <td colspan="6">
                                              <el-input v-model="addParam.bottlenolen" @input="hasChange" ref="input111" @keyup.enter.native="nextFocus(1, 11)"></el-input>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td align="right">默认批号</td>
                                          <td colspan="6">
                                              <el-input v-model="addParam.lotno" @input="hasChange" ref="input112" @keyup.enter.native="nextFocus(1, 12)"></el-input>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td align="right">默认有效期</td>
                                          <td>
                                              <el-date-picker v-model="addParam.expiredate" type="date" placeholder="开始日期" value-format="yyyy-MM-dd" style="width:155px" ref="input113" @change="hasChange">
                                              </el-date-picker>
                                          </td>
                                          <td colspan="3" align="right">对应采集部位</td>
                                          <td colspan="2">
                                              <rm-ddl-common datatype="seccode" kindno="collectionpoint" dataname="对应采集部位" v-model="addParam.collectionpoint" @change="collectionpointChange" ref="input114" width="100%"></rm-ddl-common>
                                          </td>
                                      </tr>
                                      <tr>
                                          <td align="right">血培养瓶重量(克)</td>
                                          <td>
                                              <el-input v-model="addParam.bottleweight" @input="hasChange" ref="input115" @keyup.enter.native="nextFocus(1, 15)"></el-input>
                                          </td>
                                          <td colspan="3" align="right">最小采集量(ml)</td>
                                          <td colspan="2">
                                              <el-input v-model="addParam.minblood" @input="hasChange" ref="input116" @keyup.enter.native="nextFocus(1, 16)"></el-input>
                                          </td>
                                      </tr>
                                  </table>
                              </el-tab-pane>
                              <el-tab-pane label="形态描述">
                                  <vxe-table show-overflow ref="xTable2" :data.sync="mediumResultList" :loading="mediumResultLoading" height="auto" width="100%" 
                                     border size="mini" :keyboard-local-config="keyLocalConfig" :mouse-config="{ selected: true }" resizable stripe 
                                      show-header-overflow highlight-current-row :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }">
                                      <vxe-table-column field="mediumno" title="培养基代码" width="100px" header-align="center"></vxe-table-column>
                                      <vxe-table-column field="culresult" title="培养基形态描述" :edit-render="{name:'input', events: {change: hasChange}}" width="160px" header-align="center"></vxe-table-column>
                                      <vxe-table-column field="alertflag" title="危急值" width="60" align="center">
                                          <template v-slot="{row}">
                                              <el-checkbox v-model="row.alertflag" true-label='1' false-label="0" @change="hasChange"></el-checkbox>
                                          </template>
                                      </vxe-table-column>
                                      <vxe-table-column field="defaultflag" title="默认" width="60" align="center">
                                          <template v-slot="{row}">
                                              <el-checkbox v-model="row.defaultflag" true-label='1' false-label="0" @change="hasChange"></el-checkbox>
                                          </template>
                                      </vxe-table-column>
                                      <vxe-table-column field="posflag" title="阳性" width="60" align="center">
                                          <template v-slot="{row}">
                                              <el-checkbox v-model="row.posflag" true-label='1' false-label="0" @change="hasChange"></el-checkbox>
                                          </template>
                                      </vxe-table-column>
                                      <vxe-table-column field="seq" title="序号" :edit-render="{name:'input', events: {change: hasChange}}" width="80" align="center"></vxe-table-column>
                                  </vxe-table>
                                  <div class="detail-operation">
                                      <el-button icon="el-icon-plus" class="el-button--310" @click="MainOpenDialog(5)">新增明细</el-button>
                                      <el-button icon="el-icon-caret-top" class="el-button--310" @click="MainOpenDialog(6)">插入明细</el-button>
                                      <el-button icon="el-icon-delete" class="el-button--310" @click="MainOpenDialog(7)">删除明细</el-button>
                                  </div>
                              </el-tab-pane>
                              <el-tab-pane class="text-pane" label="标本类型默认描述">
                                  <vxe-table show-overflow ref="xTable3" :data.sync="mediumSpecList" :loading="mediumSpecLoading" height="auto" width="100%" border size="mini" 
                                      :keyboard-local-config="keyLocalConfig" :mouse-config="{ selected: true }" show-header-overflow highlight-current-row resizable stripe 
                                      :edit-config="{ trigger: 'click', mode: 'row', showStatus: true, showIcon: false }">
                                      <vxe-table-column field="mediumno" title="培养基代码" width="160px" header-align="center"></vxe-table-column>
                                      <vxe-table-column field="specimencode" title="标本类型" width="100px" header-align="center">
                                          <template v-slot="{row}">
                                              <rm-ddl-common :appendtobody="true" datatype="specimen" v-model="row.specimencode" @change="specChange" ref="inputspec" style="width:100%"></rm-ddl-common>
                                          </template>
                                      </vxe-table-column>
                                      <vxe-table-column field="culresult" title="培养形态描述" :edit-render="{name:'input'}" width="160px" header-align="center">
                                          <template v-slot="{row,rowIndex}">
                                              <el-select v-model="row.culresult" filterable placeholder="请选择" @focus="selectRow(row)" @blur="selectBlur" style="margin: 0 5px;">
                                                  <el-option v-for="item in allculresultList" :key="'cul' + rowIndex + item" :label="item" :value="item"></el-option>
                                              </el-select>
                                          </template>
                                      </vxe-table-column>
                                  </vxe-table>
                                  <div class="detail-operation">
                                      <el-button icon="el-icon-plus" class="el-button--310" @click="MainOpenDialog(8)">新增明细</el-button>
                                      <el-button icon="el-icon-caret-top" class="el-button--310" @click="MainOpenDialog(9)">插入明细</el-button>
                                      <el-button icon="el-icon-delete" class="el-button--310" @click="MainOpenDialog(10)">删除明细</el-button>
                                  </div>
                              </el-tab-pane>
                          </el-tabs>
                      </div>
                  </template>
              </rm-layout-right>
          </div>
      </div>
  </div>
</template>

<script>
import XEUtils from "xe-utils";
import axios from "axios";
export default {
  name: "LIS833",
  data() {
      return {
          keyLocalConfig: {
              isArrow: true
          },
          searchParam: "",
          mediumList: [],
          fmediumList: [],
          mediumLoading: false,
          selrow: {},
          addParam: {}, // 新增 修改 字段
          faddParam: {},
          operatetype: 2, //1:新增 2:修改 3:删除
          changeflag: false,
          mediumResultList: [],
          mediumResultLoading: false,
          mediumSpecList: [],
          mediumSpecLoading: false,
          allMediumnoList: [],
          activeName: "baseinfo",
          changeMediumno: "",
          allculresultList: [],
          restaurants: ["前端", "后端", "开发", "测试"],
          form: {},
          showFile: false,
          url: "",
          updata: { action: "LIS833", override: 0 }
      };
  },
  mounted() {
      this.queryMediumList();
      this.url = this.$tool.baseUrl.replace(/api/, "z") + "fileupload";
  },
  methods: {
      queryMediumList() {
          this.mediumLoading = true;
          this.$tool
              .request({
                  url: "LIS/LIS8/LIS833",
                  method: "post",
                  data: {
                      action: "querylist"
                  }
              })
              .then(response => {
                  this.mediumLoading = false;
                  // if(response.errcode == 1) {
                  if (response.length > 0) {
                      var mediumnoList = [];
                      response.forEach(element => {
                          mediumnoList.push(element.mediumno);
                          element.updateflag = 0;
                      });
                      this.fmediumList = XEUtils.clone(response, true);
                      this.mediumList = response;
                      // this.faddParam = XEUtils.clone(response[0], true);
                      // this.addParam = XEUtils.clone(response[0], true);
                      this.allMediumnoList = mediumnoList;
                      this.selrow = response[0];
                      this.$refs.xTable.setCurrentRow(this.selrow);
                      this.queryMediumDetail(this.selrow.mediumno);
                  } else {
                      this.mediumList = [];
                  }
              })
              .catch(e => {});
      },
      queryMediumDetail(mediumno) {
          this.mediumResultLoading = true;
          this.$tool
              .request({
                  url: "LIS/LIS8/LIS833",
                  method: "post",
                  data: {
                      action: "querydetail",
                      mediumno: mediumno
                  }
              })
              .then(response => {
                  this.mediumResultLoading = false;
                  this.faddParam = XEUtils.clone(response.bactmedium, true);
                  this.addParam = response.bactmedium;
                  this.mediumResultList = response.mediumresult;
                  this.mediumSpecList = response.mediumspec;
                  if (response.mediumresult.length > 0) {
                      this.$refs.xTable2.setCurrentRow(response.mediumresult[0]);
                      var culresultList = [] ;
                      response.mediumresult.forEach(element => {
                          culresultList.push(element.culresult);
                      });
                      this.allculresultList=culresultList;
                  }
                  if (response.mediumspec.length > 0) {
                      this.$refs.xTable3.setCurrentRow(response.mediumspec[0]);
                  }
              })
              .catch(e => {});
      },
      filterData() {
          let filterName = this.searchParam.trim();
          let queryList = [];
          if (filterName) {
              this.fmediumList.filter(item => {
                  if (item.mediumno.toUpperCase().indexOf(filterName.toUpperCase()) > -1 || item.mediumname.toUpperCase().indexOf(filterName.toUpperCase()) > -1 || item.inputcode.toUpperCase().indexOf(filterName.toUpperCase()) > -1) {
                      queryList.push(item);
                  }
              });
              this.mediumList = queryList;
              if (queryList.length > 0) {
                  this.$refs.xTable.setCurrentRow(queryList[0]);
                  this.queryMediumDetail(queryList[0].mediumno);
                  this.selrow = this.$refs.xTable.getCurrentRow();
              } else {
                  this.addParam = {};
                  this.mediumResultList = [];
                  this.mediumSpecList = [];
              }
          } else {
              this.mediumList = XEUtils.clone(this.fmediumList, true);
              if (this.mediumList.length > 0) {
                  this.$refs.xTable.setCurrentRow(this.mediumList[0]);
                  this.queryMediumDetail(this.mediumList[0].mediumno);
                  this.selrow = this.$refs.xTable.getCurrentRow();
              }
          }
      },
      currentChangeEvent(e) {
          if (this.changeflag) {
              // 点击切换之前的 row
              this.$refs.xTable.setCurrentRow(this.selrow);
              return false;
          }
          this.selrow = e.row;
          this.queryMediumDetail(this.selrow.mediumno);
      },
      rowClassName({ row, rowIndex }) {
          if (row.updateflag == 1) {
              return "row-modify row--current";
          }
          if (row.updateflag == 2) {
              console.log("row-new row--current");
              return "row-new row--current";
          }
      },
      hasChange() {
          this.changeflag = true;
      },
      inputCodeChange() {
          this.addParam.inputcode = this.$pub.CreateInputcode(this.addParam.mediumname, this).substring(0, 20);
          this.hasChange();
      },
      MainOpenDialog(type) {
          if (type == 1) {
              this.operatetype = 1;
              this.hasChange();
              this.activeName = "baseinfo";
              this.addParam = {
                  noprintbar: 0,
                  bloodculture: 0,
                  autobottleno: 0
              };
              this.mediumResultList = [];
              this.mediumSpecList = [];
              setTimeout(() => {
                  this.$refs.input11.$refs.input.focus();
              }, 100);
          }
          if (type == 2) {
              // 删除
              var that = this;
              that.$confirm("确定删除这条记录?", "提示", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning"
              }).then(() => {
                  that.operatetype = 3;
                  that.$tool
                      .request({
                          url: "LIS/LIS8/LIS833",
                          method: "post",
                          data: {
                              action: "savedata",
                              mediumno: this.addParam,
                              utype: this.operatetype
                          }
                      })
                      .then(response => {
                          if (response.errcode != "1") {
                              that.$message({
                                  message: "保存失败！" + response.errmsg,
                                  type: "warning"
                              });
                          } else {
                              that.$message({
                                  message: "删除成功！",
                                  type: "success"
                              });
                              // that.QueryGroupSearch();
                              that.changeflag = false;
                              that.operatetype = 2;
                              // 删除不刷新表格
                              var delrow = this.$refs.xTable.getCurrentRow();
                              var rowindex = this.$refs.xTable.getTableData().fullData.indexOf(delrow);
                              this.mediumList.splice(rowindex, 1);
                              this.$refs.xTable.loadData(this.mediumList).then(() => {
                                  var havedata = this.$refs.xTable.getTableData().fullData;
                                  if (havedata.length > 0) {
                                      if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                                      this.fmediumList = XEUtils.clone(havedata, true);
                                      this.faddParam = XEUtils.clone(havedata[rowindex], true);
                                      this.addParam = XEUtils.clone(havedata[rowindex], true);
                                      let selectrow = havedata[rowindex];
                                      this.$refs.xTable.setCurrentRow(selectrow);
                                      this.selrow = this.$refs.xTable.getCurrentRow();
                                      this.queryMediumDetail(selectrow.mediumno);
                                  }
                              });
                              if (this.allMediumnoList.indexOf(delrow.mediumno) != -1) {
                                  this.allMediumnoList.splice(this.allMediumnoList.indexOf(delrow.mediumno), 1);
                              }
                              this.fmediumList = XEUtils.clone(havedata, true);
                              console.log(this.fmediumList);
                          }
                      })
                      .catch(e => {});
              });
          }
          if (type == 3) {
              // 保存
              this.saveSearchCondition();
          }
          if (type == 4) {
              // 取消
              this.$confirm("确定取消当前修改?", "提示", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning"
              }).then(() => {
                  if (this.operatetype == 1) {
                      this.mediumResultList = [];
                      this.mediumSpecList = [];
                  } else {
                      this.queryMediumDetail(this.selrow.mediumno);
                  }
                  this.operatetype = 2;
                  this.changeflag = false;
                  this.addParam = XEUtils.clone(this.faddParam, true);
                  this.$nextTick(() => {
                      this.$refs.xTable.setCurrentRow(this.selrow);
                  });
              });
          }
          if (type == 5) {
              this.$refs.xTable2
                  .insert({
                      mediumno: this.addParam.mediumno,
                      seq: this.$refs.xTable2.tableFullData.length > 0 ? (Math.floor(this.$refs.xTable2.tableFullData[this.$refs.xTable2.tableFullData.length - 1].seq / 10) + 1) * 10 : 10
                  })
                  .then(({ row }) => {
                      this.$nextTick(() => {
                          this.$refs.xTable2.setCurrentRow(row);
                      });
                  });
              this.hasChange();
          }
          if (type == 6) {
              this.mediumDetailTableInsert(1);
          }
          if (type == 7) {
              this.mediumDetailTableDelete(1);
          }
          if (type == 8) {
              this.$refs.xTable3
                  .insert({
                      mediumno: this.addParam.mediumno,
                      culresult: ""
                  })
                  .then(({ row }) => {
                      this.$nextTick(() => {
                          this.$refs.xTable3.setCurrentRow(row);
                      });
                  });
              this.hasChange();
          }
          if (type == 9) {
              this.mediumDetailTableInsert(2);
          }
          if (type == 10) {
              this.mediumDetailTableDelete(2);
          }
      },
      saveSearchCondition() {
          var that = this;
          if (that.addParam.mediumno == undefined || that.addParam.mediumno == "") {
              that.$alert("请输入培养基代码", "信息", {
                  confirmButtonText: "确定",
                  callback: action => {}
              });
              return false;
          }
          if (that.addParam.mediumname == undefined || that.addParam.mediumname == "") {
              that.$alert("请输入培养基名称", "信息", {
                  confirmButtonText: "确定",
                  callback: action => {}
              });
              return false;
          }
          if (that.operatetype == 1 && that.allMediumnoList.indexOf(that.addParam.mediumno) != -1) {
              that.$message({
                  message: "培养基代码冲突",
                  type: "warning"
              });
              return false;
          }
          // 排序
          that.$refs.xTable2.tableFullData.sort((a, b) => {
              return a.seq - b.seq;
          });
          that.$refs.xTable2.tableFullData.forEach((element, index) => {
              element.mediumno = that.addParam.mediumno;
              element.seq = (index + 1) * 10;
          });
          that.$refs.xTable3.tableFullData.forEach((element, index) => {
              element.mediumno = that.addParam.mediumno;
          });
          // 保存
          that.$tool
              .request({
                  url: "LIS/LIS8/LIS833",
                  method: "post",
                  data: {
                      action: "savedata",
                      mediumno: that.addParam,
                      mediumresult: that.$refs.xTable2.tableFullData,
                      mediumspec: that.$refs.xTable3.tableFullData,
                      utype: that.operatetype
                  }
              })
              .then(response => {
                  if (response.errcode != "1") {
                      that.$message({
                          message: "保存失败！" + response.errmsg,
                          type: "warning"
                      });
                  } else {
                      that.$message({
                          message: "保存成功！",
                          type: "success"
                      });
                      // this.queryMediumDetail(this.addParam.mediumno);
                      that.changeflag = false;
                      if (that.operatetype == 1) {
                          that.operatetype = 2;
                          that.$tool
                              .request({
                                  url: "LIS/LIS8/LIS833",
                                  method: "post",
                                  data: {
                                      action: "querydetail",
                                      mediumno: that.addParam.mediumno
                                  }
                              })
                              .then(response => {
                                  console.log(222);
                                  that.mediumResultLoading = false;
                                  response.bactmedium.updateflag = 2;
                                  that.faddParam = XEUtils.clone(response.bactmedium, true);
                                  that.addParam = response.bactmedium;
                                  that.mediumResultList = response.mediumresult;
                                  that.mediumSpecList = response.mediumspec;
                                  // 新增不更新表格操作
                                  that.fmediumList.push(response.bactmedium);
                                  that.mediumList.push(response.bactmedium);
                                  that.$refs.xTable.loadData(that.mediumList).then(() => {
                                      var lastrow = that.$refs.xTable.tableFullData[that.$refs.xTable.tableFullData.length - 1];
                                      that.$refs.xTable.setCurrentRow(lastrow).then(() => {
                                          that.selrow = that.$refs.xTable.getCurrentRow();
                                      });
                                  });

                                  that.allMediumnoList.push(that.addParam.mediumno);
                              })
                              .catch(e => {});
                          return false;
                      }
                      if (that.operatetype == 2) {
                          that.queryMediumDetail(that.addParam.mediumno);
                          var fcurmedium = that.fmediumList.filter(t => t.mediumno == that.selrow.mediumno);
                          that.addParam.updateflag = 1;
                          Object.keys(that.addParam).forEach(key => {
                              if (that.selrow.hasOwnProperty(key)) {
                                  that.selrow[key] = that.addParam[key];
                                  fcurmedium[0][key] = that.addParam[key];
                              }
                          });
                          that.faddParam = XEUtils.clone(that.addParam, true);
                          // that.changeMediumno = that.addParam.mediumno;
                      }
                      that.operatetype = 2;
                  }
              })
              .catch(e => {});
      },
      mediumDetailTableInsert(type) {
          if (type == 1) {
              var newRow = {
                  mediumno: this.addParam.mediumno,
                  seq: this.$refs.xTable2.tableFullData.length > 0 ? (Math.floor(this.$refs.xTable2.tableFullData[this.$refs.xTable2.tableFullData.length - 1].seq / 10) + 1) * 10 : 10
              };
              let row = this.$refs.xTable2.getCurrentRow();
              var alld = this.$refs.xTable2.getTableData().fullData;
              if (row && alld.length > 0) {
                  newRow.seq = (row.seq / 10 - 1) * 10;
                  this.$refs.xTable2.insertAt(newRow, row).then(({ row }) => {
                      this.$nextTick(() => {
                          this.$refs.xTable2.setCurrentRow(row);
                      });
                  });
              } else {
                  this.$refs.xTable2.insert(newRow).then(({ row }) => {
                      this.$nextTick(() => {
                          this.$refs.xTable2.setCurrentRow(row);
                      });
                  });
              }
          }
          if (type == 2) {
              var newRow = {
                  mediumno: this.addParam.mediumno,
                  culresult: ""
              };
              let row = this.$refs.xTable3.getCurrentRow();
              var alld = this.$refs.xTable3.getTableData().fullData;
              if (row && alld.length > 0) {
                  this.$refs.xTable3.insertAt(newRow, row).then(({ row }) => {
                      this.$nextTick(() => {
                          this.$refs.xTable3.setCurrentRow(row);
                      });
                  });
              } else {
                  this.$refs.xTable3.insert(newRow).then(({ row }) => {
                      this.$nextTick(() => {
                          this.$refs.xTable3.setCurrentRow(row);
                      });
                  });
              }
          }
          this.hasChange();
      },
      mediumDetailTableDelete(type) {
          if (type == 1) {
              var delrow = this.$refs.xTable2.getCurrentRow();
              var havedata = this.$refs.xTable2.getTableData().fullData;
              if (delrow && havedata.length > 0) {
                  var rowindex = havedata.indexOf(delrow);
                  this.$refs.xTable2.remove(delrow);
                  if (havedata.length > 0) {
                      if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                      let selectrow = this.$refs.xTable2.getTableData().fullData[rowindex];
                      this.$refs.xTable2.setCurrentRow(selectrow);
                  }
                  this.hasChange();
              } else {
                  this.$message({
                      message: "请先选中要删除的明细！",
                      type: "warning"
                  });
              }
          }
          if (type == 2) {
              var delrow = this.$refs.xTable3.getCurrentRow();
              var havedata = this.$refs.xTable3.getTableData().fullData;
              if (delrow && havedata.length > 0) {
                  var rowindex = havedata.indexOf(delrow);
                  this.$refs.xTable3.remove(delrow);
                  if (havedata.length > 0) {
                      if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                      let selectrow = this.$refs.xTable3.getTableData().fullData[rowindex];
                      this.$refs.xTable3.setCurrentRow(selectrow);
                  }
                  this.hasChange();
              } else {
                  this.$message({
                      message: "请先选中要删除的明细！",
                      type: "warning"
                  });
              }
          }
      },
      rptitemchange(code, name) {
          this.addParam.rpt_itemcode = code;
          this.addParam.rpt_itemname = name;
          this.hasChange();
      },
      collectionpointChange(code, name) {
          this.addParam.collectionpoint = code;
          this.changeflag = true;
      },
      // 回车切换输入框
      nextFocus(id, index) {
          if (index <= 15) {
              var that = this;
              var focusIndex = index + 1;
              setTimeout(function() {
                  if (index == 13) {
                      that.$refs["input" + id + index].$refs.ddlmainSelect.blur();
                  } else if (index == 5) {
                      focusIndex = index + 2;
                      that.$refs["input" + id + focusIndex].focus();
                  } else {
                      that.$refs["input" + id + focusIndex].focus();
                  }
              }, 1);
          }
      },
      specChange(code, name) {
          this.$nextTick(_ => {
              this.$refs.inputspec.$refs.ddlmainSelect.focus();
          });
          this.hasChange();
      },
      selectRow(row) {
          this.$refs.xTable3.setCurrentRow(row);
      },
      selectBlur(e) {
          var value = e.target.value;
          this.$refs.xTable3.getCurrentRow().culresult = e.target.value;
          this.hasChange();
      },
      handleTabClick(tab, event) {
          if (tab.label == "标本类型默认描述") {
              if (this.$refs.xTable2.tableFullData.length > 0) {
                  var culresultList = [];
                  this.$refs.xTable2.tableFullData.forEach(element => {
                      culresultList.push(element.culresult);
                  });
                  this.allculresultList = culresultList;
              }
          }
      },
      ExportCsv() {
          let p = { prgno: "LIS833" };
          this.$pub.commexport(this, p, `培养基.dat`);
      },
      ImportCsv() {
          this.$confirm("是否覆盖重复数据?", "提示", {
              distinguishCancelAndClose: true,
              confirmButtonText: "覆盖",
              cancelButtonText: "不覆盖",
              type: "warning"
          }).then(() => {
              this.updata.override = 1;
              this.$refs["upload"].$refs["upload-inner"].handleClick();
          })
          .catch((action) => {
              if (action === 'cancel') {
                  this.updata.override = 0;
                  this.$refs["upload"].$refs["upload-inner"].handleClick();
              }
          });
      },
      // 文件状态改变时的钩子
      fileChange(file, fileList) {
          this.form.file = file.raw;
      },
      // 上传文件之前的钩子, 参数为上传的文件,若返回 false 或者返回 Promise 且被 reject，则停止上传
      beforeUploadFile(file) {
          let extension = file.name.substring(file.name.lastIndexOf(".") + 1);
          let size = file.size / 1024 / 1024;
          if (extension !== "dat") {
              this.$notify.warning({
                  title: "警告",
                  message: `只能上传DAT(*dat)文件，且不超过10M`
              });
          }
          if (size > 10) {
              this.$notify.warning({
                  title: "警告",
                  message: `文件大小不得超过10M`
              });
          }
      },
      uploadOpt(content) {
          let formData = new FormData()
          formData.append('action', 'LIS833');
          formData.append('file', content.file);
          this.$pub.uploadFileOpt(this, formData, "queryMediumList");
      },
  }
};
</script>

<style scoped>
table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}
.page-container {
  position: absolute;
  top: 0px;
  width: 100%;
  left: 0;
  bottom: 0;
  padding: 0;
  display: flex;
}
.page-top {
  width: 100%;
  height: 38px;
  border: 1px solid #ccc;
  position: absolute;
  font-size: 12px;
  display: flex;
  padding: 5px 0;
  line-height: 24px;
}
.page-top .top-table {
  float: right;
}
.search-title {
  margin: 0 5px 0 20px;
}
.top-deal {
  right: 5px;
  position: absolute;
  height: 25px;
  display: flex;
  align-items: center;
}
.upload-button {
  height: 24px;
  margin: 0 10px;
  display: none;
}
.upload-button div {
  height: 24px;
}
.page-bottom {
  margin-top: 43px;
  position: absolute;
  font-size: 12px;
  width: 100%;
  height: calc(100% - 43px);
}
.detail-operation {
  display: flex;
  padding: 0px 2px 0px 5px;
  margin: 5px 0;
}
/deep/ .el-button.is-disabled {
  border: 0px;
  color: grey;
  background-color: #e6e6e6;
  font-weight: normal;
}
/deep/ .base-detail .el-form-item--small.el-form-item {
  margin-bottom: 0 !important;
}
/deep/ .middle-right .el-tabs--border-card > .el-tabs__content {
  overflow-y: auto;
}
/deep/ .middle-right .vxe-table {
  height: calc(100% - 31px) !important;
}
/deep/ .middle-left .vxe-table .vxe-header--column {
  line-height: 15px !important;
}
/deep/ .page-top .el-button--small {
  height: 24px !important;
}
/deep/ .middle-left tr.vxe-body--row.row-new {
  color: #cc6600;
}
/deep/ .row-modify {
  color: blue;
}
/deep/ .search-textarea .el-textarea__inner {
  padding: 5px !important;
}
/deep/ .text-pane .vxe-cell {
  padding: 0 !important;
}
/deep/ .upload-button .el-upload--text {
  border: 0 !important;
  border-radius: 3px !important;
}
/deep/ .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
  border-color: #000000;
}
</style>